#include <ros/ros.h>
#include <actionlib/client/simple_action_client.h>
#include <custom_action/customAction.h>

typedef actionlib::SimpleActionClient<custom_action::customAction> Client;

// 当action完成后会调用该回调函数一次
void doneCb(const actionlib::SimpleClientGoalState& state,
            const custom_action::customResultConstPtr& result)
{
    ROS_INFO("检测完成！");
    ros::shutdown();
}
 
// 当action激活后会调用该回调函数一次
void activeCb()
{
    ROS_INFO("开始检测了");
}
 
// 收到feedback后调用该回调函数
void feedbackCb(const custom_action::customFeedbackConstPtr& feedback)
{
    double t = feedback->feedbacknumber;
    double n = t / 40;
    ROS_INFO(" 检测进度 : %.2f%% ", n*100);
}

int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    ros::init(argc,argv,"custom_action_client_node");

    // 定义一个客户端
    Client client("custom_action", true);

    // 等待服务器端
    ROS_INFO("等待服务器响应.");
    client.waitForServer();
    ROS_INFO("服务启动, 发送目标");

    // 创建一个action的goal
    custom_action::customGoal goal;
    goal.requestnumber = 40;

    // 发送action的goal给服务器端，并且设置回调函数
    client.sendGoal(goal, &doneCb, &activeCb, &feedbackCb);

    ros::spin();
    return 0;
}
